<?php
include_once 'Node.php';

class XMLInterpreter{
	
	public function interpret(Node &$node){
		$name = $node->getAttribute('#');
		$childs = $node->getChilds();
		
		if($name != ''){
			$ret = '<'.$name;
		}else{
			$ret = '<Node noname="true"';
		}
		
		foreach ($node->attrs as $k => $v){
			if(!in_array($k[0], array('#', '>', '@'))){
				$ret .= ' '.$k.'="'.$v.'"';
			}
		}
		
		for($i=0; $i<$node->atidx; ++$i){
			$ret .= ' attr'.$i.'="'.$node->attrs['@'.$i].'"';
		}
		$ret .='>';
		
		foreach ($childs as $child){			
			$ret .= $this->interpret($child);
		}
		
		if($name != ''){
			$ret .= '</'.$name.'>';
		}else{
			$ret .= '</Node>';
		}
		return $ret;
	}
}